package com.jsj.controller;

import com.jsj.domain.Student;
import com.jsj.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/student")
public class StudentController {
    private StudentService studentService;

    @Autowired
    public void setStudentService(StudentService studentService) {
        this.studentService = studentService;
    }

    /**
     * 查询学生个人信息
     */
    @RequestMapping(value = "/queryInformation/{username}", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('student,teacher,admin')")
    public Student queryInformation(@PathVariable("username") String username) {
        Student student = studentService.queryByUserName(username);
        return student;
    }

    /**
     * 查询班级学生信息
     */
    @RequestMapping(value = "/queryByClass/{classId}", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public List<Student> queryByClass(@PathVariable("classId") int classId) {
        startPage();
        List<Student> students = studentService.queryByClass(classId);
        return students;
    }

}
